<template>
  <div class="home">
    <el-row :gutter="20">
      <el-col :span="5">
        <div class="fenlei_box">
          <div
            v-for="i in fenlei.slice(0, 5)"
            :key="i.id"
          >
            <p class="first">
              {{ i.name }}
            </p>
            <span
              v-for="items in i.productCategoryList"
              :key="items.id"
              class="second"
            >
              <a @click="goto('/shopdetail', 'ShopDetail', 935)">{{items.name}}</a>
            </span>
          </div>
          <div>
            <p class="first">
              <router-link to="/category">更多分类</router-link>
            </p>
          </div>
        </div>
      </el-col>
      <el-col :span="19">
        <el-carousel>
          <el-carousel-item>
            <img
              src="https://img2.baidu.com/it/u=665375340,1668692975&fm=253&fmt=auto&app=120&f=JPEG?w=848&h=500"
              alt
            />
          </el-carousel-item>
          <el-carousel-item>
            <img
              src="https://img0.baidu.com/it/u=3795779619,3546001334&fm=253&fmt=auto&app=120&f=JPEG?w=690&h=388"
              alt
            />
          </el-carousel-item>
        </el-carousel>
      </el-col>
    </el-row>
    <h3>精品推荐</h3>
    <div class="box">
      <div
        v-for="item in hotshop.slice(0,8)"
        :key="item.id"
        class="hotshop"
      >
        <a @click="goto('/shopdetail', 'ShopDetail', item.id)">
          <img :src="'http://139.198.178.82:9090/Shopping/' + item.defaultImg" />
          <p>{{ item.name }}</p>
          <p style="text-align: center">￥{{ item.shopPrice / 100 }}</p>
        </a>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "home",
  data() {
    return {
      bigimg: [],
      hotshop: [],
      fenlei: [],
    };
  },
  methods: {
    getimg() {
      this.$get("http://139.198.178.82:9090/Shopping/api/v1/getAllSlide").then(
        (res) => {
          if (res.errorCode == 0) {
            this.bigimg = res.data;
          }
        }
      );
    },
    // 精品推荐
    tuijian() {
      this.$post(this.url + "/product/hot", {}).then((res) => {
        if (res.errorCode == "0") {
          this.hotshop = res.data;
        }
      });
    },
    category() {
      this.$post(this.url + "category/list", {}).then((res) => {
        this.fenlei = res.data;
        console.log(this.fenlei);
      });
    },
    goto(path, name, val) {
      sessionStorage.setItem("shopid", val);
      this.$router.push({
        path: path,
        name: name,
      });
    },
  },
  created() {
    this.getimg();
    this.tuijian();
    this.category();
  },
};
</script>

<style scoped>
.home {
  width: 70%;
  margin: 0 auto;
}
.box {
  display: flex;
  flex-wrap: wrap;
}
.hotshop {
  width: 23%;
  margin: 10px;
}
img {
  max-height: 100%;
  width: 100%;
}
.first {
  margin: 0;
  text-indent: 35px;
  padding-bottom: 10px;
  font-size: 18px;
  padding-top: 10px;
}
.fenlei_box {
  background-color: black;
  /* height: 300px; */
  max-height: 100%;
  color: white;
}
.second {
  color: lightgray;
  padding-left: 20px;
}
</style>